package org.rich.charlesmurphy.core.transformer;

import org.ddevil.data.Data;
import org.ddevil.data.set.BeanDataSet;
import org.ddevil.data.set.DataSet;
import org.rich.charlesmurphy.core.Transformer;
import org.rich.charlesmurphy.model.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Rich
 */
public abstract class AbstractTransformer implements Transformer {

	protected Logger log = LoggerFactory.getLogger(getClass());


	/**
	 * {@inheritDoc}
	 */
	public DataSet<Request> transform(DataSet<Data> in) {
		log.debug("Trasforming [{}] records...", in.size());

		DataSet<Request> out = new BeanDataSet<Request>();

		for (int i = 0; i < in.size(); i++) {

			Data record = in.exportRecord(i);
//			if (acceptRecord(record, filters)) {

				Request r = transformData(record);

				out.importRecord(r);
//			}
		}
		log.debug("Transform complete. Returning [{}] records.", out.size());
		return out;
	}

	protected abstract Request transformData(Data in);

//	/**
//	 * Apply the collection of filters to a piece of data.
//	 * @param record
//	 * @param filters
//	 * @return
//	 */
//	protected boolean acceptRecord(Data record, Collection<Filter<Data>> filters) {
//		if (filters == null || filters.size() == 0) {
//			return true;
//		}
//
//		for (Filter<Data> f : filters) {
//			if (!f.accept(record)) {
//				log.debug("Filter: [{}] rejected the record.", f.getClass().getSimpleName());
//				return false;
//			}
//		}
//		return true;
//	}

}
